#!/usr/bin/env python
#coding: utf-8
'''
Created on 2017年2月22日

@author: Administrator
'''
from attachment import settings
from common.models.abstract import StateModel, TimeModel
from common.utils import storage
from django.contrib.auth.models import User
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models

class Attachment(StateModel, TimeModel):
    '''单图'''
    user = models.ForeignKey(User, verbose_name=u'用户')
    type = models.IntegerField(default=0,choices=settings.ATTACHMENT_TYPE_CHOICES,db_index=True, verbose_name=u'记录状态')
    suffix = models.CharField(default="",max_length=16,verbose_name=u'后缀')
    name = models.CharField(default=u'', blank=True, max_length=64, verbose_name=u'文件名')
    fpath = models.CharField(default=u'', blank=True, max_length=200, verbose_name=u'图片相对路径')
    width = models.SmallIntegerField(default=0, verbose_name=u'宽')
    height = models.SmallIntegerField(default=0, verbose_name=u'高')

    class Meta:
        verbose_name = u'附加文件'
        verbose_name_plural = u'附加文件'
        app_label = 'attachment'
        
    def __unicode__(self):
        return self.name
    
    @property
    def absolute_url(self):
        '''
                            绝对url
        '''
        return storage.get_absolute_url(self.fpath)